<template>
  <table class="table table-bordered table-vertical-middle" v-loading="loading">
    <tr>
      <td colspan="4" class="font-weight-bold text-center">主体基本信息</td>
    </tr>
    <tr v-if="+customer.is_approval === 2">
      <td colspan="4">
        <div>
          项目状态：
          <span class="text-danger">已拒绝</span>
        </div>
        <div>拒绝时间： {{ customer.confuse_time }}</div>
        <div>拒绝说明： {{ customer.confuse_des }}</div>
      </td>
    </tr>
    <tr>
      <td class="td-label" width="20%">主体名称</td>
      <td width="30%">
        {{ customer.customer_name || '-' }}
      </td>
      <td class="td-label" width="20%">组织类型</td>
      <td width="30%">
        {{ customer.org_class_name }}
      </td>
    </tr>
    <tr v-if="isCommon">
      <td class="td-label">负责人</td>
      <td>
        {{ customer.corp_name || '-' }}
      </td>
      <td class="td-label">营业执照</td>
      <td>
        {{ customer.register_no }}
      </td>
    </tr>
    <tr>
      <td class="td-label">身份证号（证件号）</td>
      <td>
        {{ customer.lender_idcard || '-' }}
      </td>
      <td class="td-label">联系电话</td>
      <td>
        {{ customer.mobile_no }}
      </td>
    </tr>
    <tr>
      <td class="td-label">经营地址/居住地址</td>
      <td>{{ customer.address }}</td>
      <td class="td-label">经营年限</td>
      <td>{{ customer.bussiness_years || '-' }} 年</td>
    </tr>
    <tr>
      <td colspan="4" class="font-weight-bold text-center">金融信息</td>
    </tr>
    <tr>
      <td class="td-label">资产总额</td>
      <td>{{ customer.assets_funds || '-' }} 万元</td>
      <td class="td-label">资产情况</td>
      <td>
        {{ customer.assets_des || '' }}
      </td>
    </tr>
    <tr>
      <td class="td-label">负债总额</td>
      <td>{{ customer.debt_funds || '' }} 万元</td>
      <td class="td-label">负债情况</td>
      <td>{{ customer.debt_des || '-' }}</td>
    </tr>
    <tr v-if="+customer.is_litigation === 1">
      <td class="td-label">是否涉诉</td>
      <td>
        {{ isOrN[customer.is_litigation] || '' }}
      </td>
      <td class="td-label">涉诉信息</td>
      <td>
        {{ customer.litigation_des || '' }}
      </td>
    </tr>
    <tr v-else>
      <td class="td-label">是否涉诉</td>
      <td colspan="3">
        {{ isOrN[customer.is_litigation] || '' }}
      </td>
    </tr>
    <tr>
      <td colspan="4" class="font-weight-bold text-center">贷款信息</td>
    </tr>
    <tr>
      <td class="td-label">贷款产品</td>
      <td>{{ customer.project_type_name || '' }}</td>
      <td class="td-label">贷款意向银行</td>
      <td>{{ customer.bank_name || '-' }}</td>
    </tr>
    <tr>
      <td class="td-label">申请金额</td>
      <td>{{ customer.apply_funds || '-' }} 万元</td>
      <td class="td-label">贷款年限</td>
      <td>{{ customer.load_years || '' }} 年</td>
    </tr>
    <tr>
      <td class="td-label">贷款用途</td>
      <td colspan="3">{{ customer.funds_use_dir || '-' }}</td>
    </tr>
    <tr v-if="+customer.is_recommend_letter === 0">
      <td class="td-label">是否有推荐函</td>
      <td colspan="3">否</td>
    </tr>
    <tr v-else>
      <td class="td-label">是否有推荐函</td>
      <td>{{ isOrN[customer.is_recommend_letter] }}</td>
      <td class="td-label">推荐函</td>
      <td>
        <div class="small">
          <attach-item
            v-for="(p, index) of recommendList"
            :attach-data="p"
            :key="index"
          ></attach-item>
        </div>
      </td>
    </tr>
    <tr>
      <td colspan="4" class="font-weight-bold text-center">经营信息</td>
    </tr>
    <tr>
      <td class="td-label">产业类型</td>
      <td>{{ customer.main_business }}</td>
      <td class="td-label">经营类型</td>
      <td>{{ enumBusinessType[business.business_type] }}</td>
    </tr>
    <!-- 种植类 -->
    <template v-if="+business.business_type === 1">
      <tr>
        <td class="td-label">种植品种</td>
        <td>{{ business.plant_category }}</td>
        <td class="td-label">近12个月产量</td>
        <td>{{ business.output }} 吨</td>
      </tr>
      <tr>
        <td class="td-label">种植面积</td>
        <td>{{ business.plant_area || '-' }} 亩</td>
        <td class="td-label">
          证明材料
          <div>（土地流转合同、保险单）</div>
        </td>
        <td class="small">
          <attach-item v-for="(p, index) of plantList" :attach-data="p" :key="index"></attach-item>
        </td>
      </tr>
      <tr>
        <td class="td-label">近12个月销售收入</td>
        <td>{{ business.sell_income || '-' }} 万元</td>
        <td class="td-label">
          证明材料
          <div>（银行/微信/支付宝流水、购销单据/合同）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of attachList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">是否购买农业保险</td>
        <td>{{ isOrN[business.is_buy_insurance] || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（保单）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of insuranceList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
    </template>
    <!-- 加工类 -->
    <template v-if="+business.business_type === 2">
      <tr>
        <td class="td-label">近12个月产量</td>
        <td colspan="3">{{ business.output }} 吨</td>
      </tr>
      <tr>
        <td class="td-label">厂房面积</td>
        <td>{{ business.workshop_area || '-' }} ㎡</td>
        <td class="td-label">
          证明材料
          <div>（租赁合同或产权证明）</div>
        </td>
        <td class="small">
          <attach-item v-for="(p, index) of workList" :attach-data="p" :key="index"></attach-item>
        </td>
      </tr>
      <tr>
        <td class="td-label">生产品种</td>
        <td>{{ business.produce_category || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（成品照片）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of productList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">从业人数</td>
        <td>{{ business.emp_total || '-' }} 人</td>
        <td class="td-label">
          证明材料
          <div>（工资单、工资支付凭证）</div>
        </td>
        <td>
          <div class="small">
            <attach-item v-for="(p, index) of empList" :attach-data="p" :key="index"></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">近12个月销售收入</td>
        <td>{{ business.sell_income || '-' }} 万元</td>
        <td class="td-label">
          证明材料
          <div>（银行/微信/支付宝流水、购销单据/合同）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of attachList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">是否符合国家环保政策</td>
        <td>{{ isOrN[business.is_fit_env] || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（环评报告或环评表）</div>
        </td>
        <td>
          <div class="small">
            <attach-item v-for="(p, index) of envList" :attach-data="p" :key="index"></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">近12个月税收情况</td>
        <td>{{ business.tax_des || '-' }}</td>
        <td class="td-label">
          证明材料
          <div></div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of taxDesAttachment"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
    </template>
    <template v-if="+business.business_type === 3">
      <tr>
        <td class="td-label">近12个月收入</td>
        <td>{{ business.sell_income || '-' }} 万元</td>
        <td class="td-label">
          证明材料
          <div>（银行/微信/支付宝流水、购销单据/合同）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of attachList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">是否有烘干线</td>
        <td colspan="3">{{ isOrN[business.is_dry_line] }}</td>
      </tr>
      <tr v-if="+business.is_dry_line === 1">
        <td class="td-label">烘干线数量</td>
        <td>{{ business.dry_count || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（购买发票、购买合同、现场设备照片）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of isDryLineList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">是否有固定摊位</td>
        <td colspan="3">{{ isOrN[business.is_fix_booth] }}</td>
      </tr>
      <tr v-if="+business.is_fix_booth === 1">
        <td class="td-label">摊位面积</td>
        <td>{{ business.booth_area || '-' }} ({{ enmuBoothType[business.booth_type] }})</td>
        <td class="td-label">
          证明材料
          <div>（租赁或购买合同、现场照片）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of isFixBoothList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
    </template>
    <!-- 养殖类 -->
    <template v-if="+business.business_type === 4">
      <tr>
        <td class="td-label">养殖品种</td>
        <td>{{ business.plant_category }}</td>
        <td class="td-label">近12个月产量</td>
        <td>{{ business.output }}</td>
      </tr>
      <tr>
        <td class="td-label">养殖规模</td>
        <td>{{ business.plant_area || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（土地流转合同、保险单、其他）</div>
        </td>
        <td class="small">
          <attach-item v-for="(p, index) of plantList" :attach-data="p" :key="index"></attach-item>
        </td>
      </tr>
      <tr>
        <td class="td-label">近12个月销售收入</td>
        <td>{{ business.sell_income || '-' }} 万元</td>
        <td class="td-label">
          证明材料
          <div>（银行/微信/支付宝流水、购销单据/合同）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of attachList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td-label">是否购买农业保险</td>
        <td>{{ isOrN[business.is_buy_insurance] || '-' }}</td>
        <td class="td-label">
          证明材料
          <div>（保单）</div>
        </td>
        <td>
          <div class="small">
            <attach-item
              v-for="(p, index) of insuranceList"
              :attach-data="p"
              :key="index"
            ></attach-item>
          </div>
        </td>
      </tr>
    </template>
  </table>
</template>

<script>
import { enumBusinessType } from '@/gov/views/bus/import/class/components/PepperEdit'
import AttachItem from '@/bank/components/attach/Item'
import { attachAdapter } from '@/bank/components/attach/index'
import { arrayFromString } from '@vimi/utils-tool'
export default {
  components: {
    AttachItem,
  },
  props: {
    queryId: String,
  },
  data() {
    return {
      enmuBoothType: {
        1: '租赁',
        2: '自有',
      },
      enumBusinessType,
      isOrN: {
        0: '否',
        1: '是',
      },
      loading: false,
      tableName: 'credit_industrial',
      customer: {},
    }
  },
  computed: {
    isCommon() {
      return +this.customer.customer_type === 1
    },
    business() {
      return this.customer.credit_industrial_pepper?.[0] ?? {}
    },
    recommendList() {
      return this.getAttach(this.customer.recommend_letter_attachment)
    },
    workList() {
      return this.getAttach(this.business.workshop_attachment)
    },
    productList() {
      return this.getAttach(this.business.pro_category_attachment)
    },
    empList() {
      return this.getAttach(this.business.emp_attachment)
    },
    attachList() {
      return this.getAttach(this.business.income_attachment)
    },
    envList() {
      return this.getAttach(this.business.env_attachment)
    },
    plantList() {
      return this.getAttach(this.business.plant_attachment)
    },
    insuranceList() {
      return this.getAttach(this.business.ins_attachment)
    },
    isDryLineList() {
      return this.getAttach(this.business.dry_attachment)
    },
    isFixBoothList() {
      return this.getAttach(this.business.booth_attachment)
    },
    taxDesAttachment() {
      return this.getAttach(this.business.tax_des_attachment)
    },
  },
  watch: {
    queryId: {
      handler: function () {
        this.getData()
      },
      immediate: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    getAttach(data) {
      return arrayFromString(data).map(img => {
        return attachAdapter({ attachment: img })
      })
    },
    getData() {
      if (!this.queryId) {
        return
      }
      this.loading = true
      this.$api
        .getData(this.$serviceName, this.tableName, {
          'credit_industrial_id.eq': this.queryId,
          subKey: 'credit_industrial_pepper.credit_industrial_id',
        })
        .then(res => {
          this.customer = res?.data?.[0] ?? {}
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>

<style lang="scss" scoped>
.table-vertical-middle td {
  vertical-align: middle;
}
.td-label {
  background-color: #f8f9fa;
  text-align: center;
}
</style>
